import {Component} from '@angular/core';
import {Router, Routes} from '@angular/router';
import {environment} from '../environments/environment';
import {routes} from './app-routing.module';
import {loadRemoteModule} from '@angular-architects/module-federation';

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss'],
})
export class AppComponent {

    constructor(
        private router: Router,
    ) {
    }

    ngOnInit() {
        let newRoutes: Routes = [
            {
                path: 'plugin002',
                loadChildren: () => loadRemoteModule({
                    type: 'module',
                    exposedModule: './AppModule',
                    remoteEntry: environment.production ? '/assets/federation-plugin002/remoteEntry.js' : 'http://localhost:4201/remoteEntry.js',
                }).then(m => this.resolveModule(m)),
            },
            ...routes,
        ];
        this.router.resetConfig(newRoutes);
    }

    resolveModule(m: any) {
        console.log('m', m)
        return m.AppModule
    }
}
